/*
 * !Drowning
 * May 29, 2011
 * TCSS 360
 * Schedule Project
 */
import java.util.ArrayList;
import java.util.List;

/**
 * Course contain information for the single course.
 * 
 * @author Efim Todorasco
 * @author Al McKenzie modified and reviewed
 * @version May 29. 2011
 */
public class Course {
	private String my_course_id;
	private String my_class_title;
	private int my_credits;
	private List<List> my_sections = new ArrayList<List>();
	
	/**
	 * Constructor for the course.
	 * @param the_parameters The parameters.
	 */
	public Course (List<String> the_parameters){
		my_course_id = the_parameters.get(0);
		my_class_title = the_parameters.get(2);
		my_credits = Integer.parseInt(the_parameters.get(7)); 	
		add(the_parameters);
	}
	
	/**
	 * This method will add alternate sections.
	 * @param the_parameters [courseId, section, title, instru, days, stime, etime, credits]
	 */
	public void add(List<String> the_parameters){
		String the_section = the_parameters.get(1);
		String the_instructor = the_parameters.get(3);
		String the_days = the_parameters.get(4);
		int the_start_time = Integer.parseInt(the_parameters.get(5)); 
		int the_end_time = Integer.parseInt(the_parameters.get(6)); 
		
		List a_section = new ArrayList();
		a_section.add(0, the_section);
		a_section.add(1, the_instructor);
		a_section.add(2, the_days);
		a_section.add(3, the_start_time);
		a_section.add(4, the_end_time);	
		my_sections.add(a_section);
	}
	
	/**
	 * Returns toString representation of the course
	 */
	public String toString() {	
		StringBuilder sbr = new StringBuilder();
		sbr.append("CourseID: " + my_course_id + "\t");
		sbr.append("Class title : " + my_class_title + "\t");
		sbr.append("Credits " + (my_credits == -1 ? "TBA":my_credits + "\t"));
		for(List a : my_sections)
		{
		    sbr.append("\n");
			sbr.append("Section: " + a.get(0)+ "\t");
			sbr.append("Days: " + a.get(2)+ "\t");
			sbr.append("Time: " + a.get(3)+ " - " + a.get(4) + "\t");
			sbr.append("Instructor: " + a.get(1));
			
		}
		sbr.append("\n");
		
		return sbr.toString();
		
		
	}

	/***
	 * This method will get sections of a course and return a list of them.
	 * @return a String list of course sections, a,b,c,etc...
	 */
	public String[] getSectionNames(){
        String[] the_sections = new String[my_sections.size()];
        for(int i = 0; i < my_sections.size(); i++){
                the_sections[i] = (String) my_sections.get(i).get(0);
        }
        return the_sections;
    }
	
	/***
	 * This method returns the complete list of section specific information.
	 * @return the sections.
	 */
	public List<List> getSections(){
		return my_sections;
	}


	/**
	 * Returns course ID (TCSS343)
	 * @return course id
	 */
	public String getId() {
		return my_course_id;
	}

	/**
	 * 
	 * @return course title.
	 */
	public String getTitle() {
		return my_class_title;
	}

	/**
	 * The method can change the course name.
	 * @param my_class_title new name of class
	 */
	public void setClassTitle(String my_class_title) {
		this.my_class_title = my_class_title;
	}

	/**
	 * 
	 * @param section section we are looking for.
	 * @return instructor for a given section else -1
	 */
	public String getInstructor(String section) {
		for(List a : my_sections)
		{
			if(a.get(0).equals(section))
			{
				return (String) a.get(1);
			}
		}
		
		return null;
	}

	public String getDays(String section) {
		for(List a : my_sections)
		{
			if(a.get(0).equals(section))
			{
				return (String) a.get(2);
			}
		}
		
		return null;
		
	}

	public int getStartTime(String section) {
		for(List a : my_sections)
		{
			if(a.get(0).equals(section))
			{
				return (Integer) a.get(3);
			}
		}
		
		return -1;
	}

	public int getEndTime(String section) {
		for(List a : my_sections)
		{
			if(a.get(0).equals(section))
			{
				return (Integer) a.get(4);
			}
		}
		
		return -1;
	}

	public int getCredits() {
		return my_credits;
	}
	
	public void getCSV(String the_sections)
	{
		//string builder...
	}

}
